import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    SelectButton,
    DelDataButton,
    ExecuteButton,
    TestDetailsButton,
    SelectExcelButton,
    ModDataButton,
    OpenSelection,
} from '../Common/options'
import { LabHandleType, DataSynchronization, ProjectList } from '../Common/Conversion'

export const LabStressMachine = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    const labHandleType = await LabHandleType()
    const centNameOptions = await DataSynchronization()

    let data = {
        pageSize: 10,
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        params: { pageIndex: 1, equipmentType: '压力机' },
        options: [
            // 批量审核
            Permission.findIndex(v => v.uuid === '50952a05-0b58-47c5-b7c5-9e5f08bf4277') !== -1 && (
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量审核"
                    data={{
                        type: 'SelectLabAuditStatus',
                        value2: 'LabStressMachineMapping',
                        url: 'posUpdateAuditStatus',
                    }}
                />
            ),
            // 批量填写原因
            Permission.findIndex(v => v.uuid === '7f3021dd-f43d-409c-87dd-57c7cf5051b2') !== -1 && (
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量填写原因"
                    data={{
                        type: 'SelectLabHandleType',
                        handle: labHandleType,
                        value2: 'LabStressMachineMapping',
                        url: 'posUpdateLabHandleType',
                    }}
                />
            ),
            <SelectExcelButton
                key="excel"
                title="下载Excel"
                OptionsEvent={OptionsEvent}
                api={API_LIST()['getLabStressMachineExcel']}
            />,
        ],
        columns: [
            commonTableList.uuid,
            {
                ...commonTableList.SearchSort,
                selectType: 'LabStressMachine',
            },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'ownerOrganizationName',
                title: '样品来源',
                valueType: 'input',
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'projectName',
                title: '工程名称',
                valueType: 'input',
                ellipsis: true,
                width: 150,
            },
            {
                dataIndex: 'constructionSpot',
                title: '施工部位',
                valueType: 'input',
                width: 250,
                ellipsis: true,
            },
            {
                dataIndex: 'testType',
                title: '试验类别',
                valueType: 'input',
                ellipsis: true,
                width: 250,
            },
            {
                dataIndex: 'testDate',
                title: '试验日期',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'cubeCode',
                title: '试件编号',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'concreteAge',
                title: '龄期',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'designStrength',
                title: '设计强度',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'representativeStrength',
                title: '强度代表值',
                hideInSearch: true,
                valueType: 'input',
                render: (_, { representativeStrength }) => {
                    return <div> {parseInt(representativeStrength * 100) / 100} </div>
                },
                width: 150,
            },
            {
                dataIndex: 'testEvaluation',
                title: '评定结果',
                valueType: 'select',
                valueEnum: BuiltInData.result,
                width: 150,
            },
            {
                dataIndex: 'labHandleTypeUuid',
                title: '处理意见',
                valueType: 'select',
                hideInModify: true,
                ellipsis: true,
                valueEnum: labHandleType,
                width: 180,
            },

            {
                dataIndex: 'remark',
                title: '说明',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                ellipsis: true,
                width: 400,
            },
            {
                dataIndex: 'handleUserName',
                title: '填报人',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'handleTime',
                title: '填报时间',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditStatus',
                title: '审核状态',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditor',
                title: '审核人',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditDate',
                title: '审核时间',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                ...commonTableList.isEnabled,
                rules: true,
                hideInSearch: false,
                hideInModify: true,
            },

            {
                dataIndex: 'equipmentNumber',
                title: '设备编号',
                valueType: 'input',
                hideInSearch: true,
                width: 150,
            },
            {
                dataIndex: 'equipmentName',
                title: '试验机名称',
                valueType: 'input',
                width: 400,
            },
            // {
            //     dataIndex: 'equipmentType',
            //     title: '设备类别',
            //     valueType: 'select',
            //     valueEnum: {
            //         压力机: '压力机',
            //         抗折抗压一体机: '抗折抗压一体机',
            //     },
            //     width: 150,
            // },
            {
                dataIndex: 'synced',
                title: '同步',
                valueType: 'select',
                valueEnum: {
                    0: '未同步',
                    1: '已同步',
                },
                width: 150,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },

            commonTableList.BeginStatDate,
            commonTableList.EndStatDate,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 500,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, labHandleTypeUuid, isEnabled, synced } = record
                    return [
                        Permission.findIndex(v => v.uuid === 'e91d95ac-6e08-4224-9289-235fc1e577b8') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        <TestDetailsButton
                            key="test"
                            title="试验详情"
                            OptionsEvent={OptionsEvent}
                            data={{
                                type: 'LabStressMachine',
                                title: '压力机试验详情',
                                data: { uuid },
                            }}
                        />,
                        <SelectButton
                            key="select"
                            title="样品来源"
                            OptionsEvent={OptionsEvent}
                            data={{
                                actionRef,
                                options: ClientData.organization,
                                label: '样品来源',
                                url: 'posLabStressMachineSetOwner',
                                uuid: record.uuid,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === 'aa950b1d-4f36-4b75-818f-1a51d99b1c54') !== -1 &&
                            synced === 0 && (
                                <SelectButton
                                    key="upload"
                                    title="上传数据"
                                    OptionsEvent={OptionsEvent}
                                    data={{
                                        actionRef,
                                        options: centNameOptions,
                                        label: '上传平台',
                                        url: 'posBCCenterPushPushLabStressMachine',
                                        uuid: record.uuid,
                                    }}
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'e91d95ac-6e08-4224-9289-235fc1e577b8') !== -1 &&
                            isEnabled !== 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="启用"
                                    url="patLabStressMachine"
                                    path={[uuid, 1]}
                                    tips="数据启用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'e91d95ac-6e08-4224-9289-235fc1e577b8') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="禁用"
                                    danger={true}
                                    url="patLabStressMachine"
                                    path={[uuid, 0]}
                                    tips="数据禁用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '168921a6-05b6-41be-9f77-6cdc5b07319e') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
